package com.ease.util.reflection {

   import com.ease.util.ProfilingManager;
   import com.ease.util.StringUtils;

   /**
    * Represents meta tags reflection info.
    */
   public class TagReflectionInfo {
      /**
       * The tag name.
       */
      public var name:String;

      /**
       * The tag arguments, or null if none.
       */
      public var argInfos:Vector.<TagArgReflectionInfo>;

      /**
       * Adds an argument to this tag.
       */
      public function addArg(argInfo:TagArgReflectionInfo):void {
         if (this.argInfos == null) {
            this.argInfos = new Vector.<TagArgReflectionInfo>();
         }
         this.argInfos.push(argInfo);
      }

      /**
       * Returns the argument having the given key, or null if none.
       */
      public function getArgInfoByKey(key:String):TagArgReflectionInfo {
         for each (var argInfo:TagArgReflectionInfo in this.argInfos) {
            if (argInfo.key == key) {
               return argInfo;
            }
            if (StringUtils.isNullorEmpty(key) && StringUtils.isNullorEmpty(argInfo.key)) {
               return argInfo;
            }
         }
         return null;
      }

      /**
       * @see ProfilingManager.getObjectSize.
       */
      public function getNestedSize():int {
         var size1:int = ProfilingManager.instance.getObjectSize(this.name);
         var size2:int = ProfilingManager.instance.getObjectSize(this.argInfos);
         return  size1 + size2;
      }
   }
}